<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript" src="../js/jquery-3.6.0.min.js"></script>
<body>
<form id="addForm">
    <input type="hidden" name="demoid"/>
    姓名<input type="text" name="demoname"/>
    <input type="button" value="提交" onclick="saveBtn()"/>
</form>
</body>
<script>
    function saveBtn(){
        $.ajax({
            url: "../demo/addDemo",
            type: "post",
            data: $("#addForm").serialize(),
            success:function (data){
                alert("添加成功!");
                location.href="../demo/show";
            },error:function (){
                alert("添加失败!");
            }
        })
    }
</script>
</html>